import React, { Suspense } from 'react'
import { Router, Switch, Route } from 'react-router-dom'
import { Provider } from 'react-redux'
import { History } from 'history'
import store from '@stores/index'
import App from './index'
import { Spin } from 'antd'
import * as styles from './index.scss'

const Home = React.lazy(() => import('@pages/Home'))
const Error = React.lazy(() => import('@pages/Error')) // 404页面

const AppRouter = (history: History) => {
  return (
    <Provider store={store}>
      <Router history={history}>
        <App>
          <Suspense fallback={
            <div className={styles.loading}>
              <Spin size='large' />
            </div>
          }>
            <Switch>
              <Route path='/' exact component={Home} />
              <Route component={Error} />
            </Switch>
          </Suspense>
        </App>
      </Router>
    </Provider>
  )
}

export default AppRouter
